import 'package:flutter/widgets.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/src/foundation/portal/portal_spacing.dart';

void main() {
  for (final (Alignment child, Alignment portal, Offset expected) in [
    (.topLeft, .topLeft, .zero),
    (.topLeft, .topCenter, .zero),
    (.topLeft, .topRight, const Offset(-1, 0)),
    (.topLeft, .centerLeft, .zero),
    (.topLeft, .center, .zero),
    (.topLeft, .centerRight, const Offset(-1, 0)),
    (.topLeft, .bottomLeft, const Offset(0, -1)),
    (.topLeft, .bottomCenter, const Offset(0, -1)),
    (.topLeft, .bottomRight, const Offset(-1, -1)),
    //
    (.topCenter, .topLeft, .zero),
    (.topCenter, .topCenter, .zero),
    (.topCenter, .topRight, .zero),
    (.topCenter, .centerLeft, .zero),
    (.topCenter, .center, .zero),
    (.topCenter, .centerRight, .zero),
    (.topCenter, .bottomLeft, const Offset(0, -1)),
    (.topCenter, .bottomCenter, const Offset(0, -1)),
    (.topCenter, .bottomRight, const Offset(0, -1)),
    //
    (.topRight, .topLeft, const Offset(1, 0)),
    (.topRight, .topCenter, .zero),
    (.topRight, .topRight, .zero),
    (.topRight, .centerLeft, const Offset(1, 0)),
    (.topRight, .center, .zero),
    (.topRight, .centerRight, .zero),
    (.topRight, .bottomLeft, const Offset(1, -1)),
    (.topRight, .bottomCenter, const Offset(0, -1)),
    (.topRight, .bottomRight, const Offset(0, -1)),
    //
    (.centerLeft, .topLeft, .zero),
    (.centerLeft, .topCenter, .zero),
    (.centerLeft, .topRight, const Offset(-1, 0)),
    (.centerLeft, .centerLeft, .zero),
    (.centerLeft, .center, .zero),
    (.centerLeft, .centerRight, const Offset(-1, 0)),
    (.centerLeft, .bottomLeft, .zero),
    (.centerLeft, .bottomCenter, .zero),
    (.centerLeft, .bottomRight, const Offset(-1, 0)),
    //
    (.center, .topLeft, .zero),
    (.center, .topCenter, .zero),
    (.center, .topRight, .zero),
    (.center, .centerLeft, .zero),
    (.center, .center, .zero),
    (.center, .centerRight, .zero),
    (.center, .bottomLeft, .zero),
    (.center, .bottomCenter, .zero),
    (.center, .bottomRight, .zero),
    //
    (.centerRight, .topLeft, const Offset(1, 0)),
    (.centerRight, .topCenter, .zero),
    (.centerRight, .topRight, .zero),
    (.centerRight, .centerLeft, const Offset(1, 0)),
    (.centerRight, .center, .zero),
    (.centerRight, .centerRight, .zero),
    (.centerRight, .bottomLeft, const Offset(1, 0)),
    (.centerRight, .bottomCenter, .zero),
    (.centerRight, .bottomRight, .zero),
    //
    (.bottomLeft, .topLeft, const Offset(0, 1)),
    (.bottomLeft, .topCenter, const Offset(0, 1)),
    (.bottomLeft, .topRight, const Offset(-1, 1)),
    (.bottomLeft, .centerLeft, .zero),
    (.bottomLeft, .center, .zero),
    (.bottomLeft, .centerRight, const Offset(-1, 0)),
    (.bottomLeft, .bottomLeft, .zero),
    (.bottomLeft, .bottomCenter, .zero),
    (.bottomLeft, .bottomRight, const Offset(-1, 0)),
    //
    (.bottomCenter, .topLeft, const Offset(0, 1)),
    (.bottomCenter, .topCenter, const Offset(0, 1)),
    (.bottomCenter, .topRight, const Offset(0, 1)),
    (.bottomCenter, .centerLeft, .zero),
    (.bottomCenter, .center, .zero),
    (.bottomCenter, .centerRight, .zero),
    (.bottomCenter, .bottomLeft, .zero),
    (.bottomCenter, .bottomCenter, .zero),
    (.bottomCenter, .bottomRight, .zero),
    //
    (.bottomRight, .topLeft, const Offset(1, 1)),
    (.bottomRight, .topCenter, const Offset(0, 1)),
    (.bottomRight, .topRight, const Offset(0, 1)),
    (.bottomRight, .centerLeft, const Offset(1, 0)),
    (.bottomRight, .center, .zero),
    (.bottomRight, .centerRight, .zero),
    (.bottomRight, .bottomLeft, const Offset(1, 0)),
    (.bottomRight, .bottomCenter, .zero),
    (.bottomRight, .bottomRight, .zero),
  ]) {
    test(
      'default portal spacing, diagonals - $child -$portal',
      () => expect(const FPortalSpacing(1, diagonal: true).call(child, portal), expected),
    );
  }

  for (final (Alignment child, Alignment portal, Offset expected) in [
    (.topLeft, .topLeft, .zero),
    (.topLeft, .topCenter, .zero),
    (.topLeft, .topRight, const Offset(-1, 0)),
    (.topLeft, .centerLeft, .zero),
    (.topLeft, .center, .zero),
    (.topLeft, .centerRight, const Offset(-1, 0)),
    (.topLeft, .bottomLeft, const Offset(0, -1)),
    (.topLeft, .bottomCenter, const Offset(0, -1)),
    (.topLeft, .bottomRight, .zero),
    //
    (.topCenter, .topLeft, .zero),
    (.topCenter, .topCenter, .zero),
    (.topCenter, .topRight, .zero),
    (.topCenter, .centerLeft, .zero),
    (.topCenter, .center, .zero),
    (.topCenter, .centerRight, .zero),
    (.topCenter, .bottomLeft, const Offset(0, -1)),
    (.topCenter, .bottomCenter, const Offset(0, -1)),
    (.topCenter, .bottomRight, const Offset(0, -1)),
    //
    (.topRight, .topLeft, const Offset(1, 0)),
    (.topRight, .topCenter, .zero),
    (.topRight, .topRight, .zero),
    (.topRight, .centerLeft, const Offset(1, 0)),
    (.topRight, .center, .zero),
    (.topRight, .centerRight, .zero),
    (.topRight, .bottomLeft, .zero),
    (.topRight, .bottomCenter, const Offset(0, -1)),
    (.topRight, .bottomRight, const Offset(0, -1)),
    //
    (.centerLeft, .topLeft, .zero),
    (.centerLeft, .topCenter, .zero),
    (.centerLeft, .topRight, const Offset(-1, 0)),
    (.centerLeft, .centerLeft, .zero),
    (.centerLeft, .center, .zero),
    (.centerLeft, .centerRight, const Offset(-1, 0)),
    (.centerLeft, .bottomLeft, .zero),
    (.centerLeft, .bottomCenter, .zero),
    (.centerLeft, .bottomRight, const Offset(-1, 0)),
    //
    (.center, .topLeft, .zero),
    (.center, .topCenter, .zero),
    (.center, .topRight, .zero),
    (.center, .centerLeft, .zero),
    (.center, .center, .zero),
    (.center, .centerRight, .zero),
    (.center, .bottomLeft, .zero),
    (.center, .bottomCenter, .zero),
    (.center, .bottomRight, .zero),
    //
    (.centerRight, .topLeft, const Offset(1, 0)),
    (.centerRight, .topCenter, .zero),
    (.centerRight, .topRight, .zero),
    (.centerRight, .centerLeft, const Offset(1, 0)),
    (.centerRight, .center, .zero),
    (.centerRight, .centerRight, .zero),
    (.centerRight, .bottomLeft, const Offset(1, 0)),
    (.centerRight, .bottomCenter, .zero),
    (.centerRight, .bottomRight, .zero),
    //
    (.bottomLeft, .topLeft, const Offset(0, 1)),
    (.bottomLeft, .topCenter, const Offset(0, 1)),
    (.bottomLeft, .topRight, .zero),
    (.bottomLeft, .centerLeft, .zero),
    (.bottomLeft, .center, .zero),
    (.bottomLeft, .centerRight, const Offset(-1, 0)),
    (.bottomLeft, .bottomLeft, .zero),
    (.bottomLeft, .bottomCenter, .zero),
    (.bottomLeft, .bottomRight, const Offset(-1, 0)),
    //
    (.bottomCenter, .topLeft, const Offset(0, 1)),
    (.bottomCenter, .topCenter, const Offset(0, 1)),
    (.bottomCenter, .topRight, const Offset(0, 1)),
    (.bottomCenter, .centerLeft, .zero),
    (.bottomCenter, .center, .zero),
    (.bottomCenter, .centerRight, .zero),
    (.bottomCenter, .bottomLeft, .zero),
    (.bottomCenter, .bottomCenter, .zero),
    (.bottomCenter, .bottomRight, .zero),
    //
    (.bottomRight, .topLeft, .zero),
    (.bottomRight, .topCenter, const Offset(0, 1)),
    (.bottomRight, .topRight, const Offset(0, 1)),
    (.bottomRight, .centerLeft, const Offset(1, 0)),
    (.bottomRight, .center, .zero),
    (.bottomRight, .centerRight, .zero),
    (.bottomRight, .bottomLeft, const Offset(1, 0)),
    (.bottomRight, .bottomCenter, .zero),
    (.bottomRight, .bottomRight, .zero),
  ]) {
    test(
      'default portal spacing, no diagonals - $child -$portal',
      () => expect(const FPortalSpacing(1).call(child, portal), expected),
    );
  }
}
